<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page language="java" import="java.util.*" %>
<jsp:directive.page import="com.xr.common.CommUtil"/>
<jsp:directive.page import="com.bstek.dorado.data.db.*"/>
<jsp:directive.page import="com.bstek.dorado.utils.variant.VariantSet"/>
<html>
  <head>
    <title></title>
<script language="javascript" src="<%=request.getContextPath()%>/dorado/smartweb2.loadUserLib.d?file=/lib/jquery1.8.2.min.js"></script>
 <script  src="<%=request.getContextPath()%>/dorado/smartweb2.loadUserLib.d?file=/lib/highcharts2.3.5.js"></script>
<script   src="<%=request.getContextPath()%>/dorado/smartweb2.loadUserLib.d?file=/lib/exporting2.3.5.js"></script>
<script type="text/javascript">
		<%
		String c="",cmc="",cfc="";
		int sum=0;
		String comId=request.getParameter("comId");
			DBStatement dbs=new  DBStatement();
			dbs.setSql("select " +
	  		"age," +
	  		"(select count(1) from org_employee emp,org_onoff_station oos where oos.employee_id=emp.employee_id " +
	  		"and oos.status=2 and emp.sex=0 and oos.company_id in(" +
	  		"select com.company_id from org_company com  start with com.company_id="+comId+" CONNECT BY prior com.company_id=com.super_company_id) " +
	  		"and Floor(to_char(emp.birthday,'yy')/10)=age)man," +
	  		"(select count(1) from org_employee emp,org_onoff_station oos where oos.employee_id=emp.employee_id " +
	  		"and oos.status=2 and emp.sex=1 and oos.company_id in(" +
	  		"select com.company_id from org_company com  start with com.company_id="+comId+" CONNECT BY prior com.company_id=com.super_company_id) " +
	  		"and Floor(to_char(emp.birthday,'yy')/10)=age)flame " +
	  		"from " +
	  		"(select distinct Floor(to_char(emp.birthday,'yy')/10)age from org_employee emp,org_onoff_station oos where oos.employee_id=emp.employee_id " +
	  		"and oos.status=2 and emp.sex is not null and emp.birthday is not null and oos.company_id in(" +
	  		"select com.company_id from org_company com  start with com.company_id="+comId+" CONNECT BY prior com.company_id=com.super_company_id) order by age)");
			List list=dbs.queryForList();
			if(list.size()==0){out.write("</script><body>该公司无数据被统计！<body>"); return;}
			for(int i=0;i<list.size();i++){
			  VariantSet vs=(VariantSet)list.get(i);
			   c+=vs.getString("age")+"0-"+vs.getString("age")+"9','";
			   cmc+="-"+vs.getString("man")+",";
			   cfc+=""+vs.getString("flame")+",";
			   
			   sum= vs.getInt("man")>sum?vs.getInt("man"):sum;
			   sum= vs.getInt("flame")>sum?vs.getInt("flame"):sum;
			}
			c=c.substring(0,c.length()-2);
			cfc=cfc.substring(0,cfc.length()-1);
			cmc=cmc.substring(0,cmc.length()-1);
			dbs.close();
		%>
			var chart,
				categories = ['<%=c%>];
			  $(document).ready(function() {
                                    chart = new Highcharts.Chart({
                                        chart: {
                                            renderTo: 'container',
                                            type: 'bar'
                                        },
					title: {
						text: ''
					},
					subtitle: {
						text: ''
					},
					xAxis: [{
						categories: categories,
						reversed: false
					}, { // mirror axis on right side
						opposite: true,
						reversed: false,
						categories: categories,
						linkedTo: 0
					}],
					yAxis: {
						title: {
							text: null
						},
						labels: {
							formatter: function(){
								return (Math.abs(this.value)) + '';
							}
						},
						min: -<%=sum%>,
						max: <%=sum%>
					},
					
					plotOptions: {
						series: {
							stacking: 'normal'
						}
					},
					
					tooltip: {
						formatter: function(){
							return '<b>'+ this.series.name +', 年代 '+ this.point.category +'</b><br/>'+
								 '人数: '+ Highcharts.numberFormat(Math.abs(this.point.y), 0);
						}
					},
					
					series: [{
						name: '男',
						data: [<%=cmc%>]
					}, {
						name: '女',
						data: [<%=cfc%>]
					}]
				});
			});
 		
		</script>

  </head>
  
  <body>
  <%
	String yy=CommUtil.functionPrower("jsp/org/orgStatMain.jsp");
		 	if(!yy.equals("")){
		 	  out.println(yy);
		 	  return;
		 	}
 %>

    <div id="container" style="min-width: 400px; max-width: 800px; height: 350px; margin: 0 auto"></div>

  </body>
</html>
